#!/usr/bin/env python

#
# topological-hex, a program to compute combinatorial hexahedral meshes.
#
# Copyright (C) <2018> <Université catholique de Louvain (UCL), Belgique>
#
# List of the contributors to the development, description and complete License:
# see LICENSE file.
#
# This program (topological-hex) is free software:
# you can redistribute it and/or modify it under the terms
# of the GNU General Public License as published by the Free
# Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program (see COPYING file).  If not,
# see <http://www.gnu.org/licenses/>.
#

from gmshpy.gmshGeo  import GModel
from gmshpy.gmshMesh import MeshQualityOptimizer, MeshQualOptParameters

import sys

if len(sys.argv) != 3:
    print("Usage: ", sys.argv[0], " INPUT OUTPUT")
    exit(1)

model = GModel()
model.readMESH(sys.argv[1])

options = MeshQualOptParameters()
options.onlyValidity = False
options.fixedBndNodes = True
options.dim = 3
options.nCurses = 1
options.maxOptIter = 1000
options.maxBarrierUpdates = 300
options.minTargetIdealJac = 1.0
options.minTargetInvCondNum = 1.0

MeshQualityOptimizer(model, options)

model.writeMESH(sys.argv[2])
